package dicky.fortunetelling;


import org.json.JSONObject;

import dicky.fortunetelling.logic.DataArray;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class numberfortune extends Activity {
	private Button btn1;
	private EditText edit1;
	private TextView text1,text2;
	
	private String tag=numberfortune.class.getSimpleName();
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.numberfortune);
        
        btn1=(Button)findViewById(R.id.button1);
        btn1.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				numberfortune();
			}
		});
        
        edit1=(EditText)findViewById(R.id.edit1);
        
        text1=(TextView)findViewById(R.id.text1);
        text2=(TextView)findViewById(R.id.text2);
    }
	
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			if (getCurrentFocus() != null
					&& getCurrentFocus().getWindowToken() != null) {
				manager.hideSoftInputFromWindow(getCurrentFocus()
						.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
			}
		}
		return super.onTouchEvent(event);

	}
	
	private void numberfortune(){
		try{
			int i=Integer.parseInt(edit1.getText().toString());
			i=i%80;
			if(i==0){
				i=80;
			}
			text1.setText(i%80+"");
			text2.setText(DataArray.GetNumber1(i)+"\n\n"+DataArray.GetNumber2(i));
		} catch (Exception ex) {
			Toast.makeText(numberfortune.this, "录入数据有误", Toast.LENGTH_LONG).show();
		}
	}
}
